// pages/post/post.js
const app = getApp()
const db = wx.cloud.database()

Page({

  data: {
    post_detail:{},
    allPostData:[],
    postList :[]
  },

  dianZan: function () {
    var thePostData1 = this.data.post_detail;
    if (thePostData1.upStatus == true) {
      thePostData1.upStatus = false;
      thePostData1.collectionNum--;
    } else {
      thePostData1.upStatus = true;
      thePostData1.collectionNum++;
    }
    this.setData({
      post_detail: thePostData1,
    });
    //更新缓存
    var allPostData1 = wx.getStorageSync('allPostData');
    var id = thePostData1.postId;
    for (var i = 0; i < allPostData1.length; i++) {
      if (id == allPostData1[i].postId) {
        allPostData1[i] = thePostData1;
        break;
      }
    }
    wx.setStorageSync('allPostData', allPostData1);
  },

  onLoad: function () {
    var that = this
    
    db.collection('postList')
    .get({
      success:function(res){
        console.log(res.data[0].postList)
        that.setData({
          postList: res.data[0].postList
        })
      }
    })
  
  }
})
// var dataObj = require("../../data/data.js");
// this.setData({
// postList: dataObj.allPostDataExport,
// }) 

// var postsData = wx.getStorageSync('allPostData');
// this.setData({
// postList: postsData
// });
// },



/**
* 生命周期函数--监听页面显示
*/


/**
* 生命周期函数--监听页面隐藏
*/

/**
* 生命周期函数--监听页面卸载
*/
/**
* 页面相关事件处理函数--监听用户下拉动作
*/

/**
* 页面上拉触底事件的处理函数
*/

/**
* 用户点击右上角分享
*/
